package com.six.backend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @Author: skyler
 * @Date: 2021/11/8 12:41
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //basepackage:配置要扫描的包
                //any():扫描全部
                //none():不扫描
                //withClassAnnotation:扫描类上的注解,参数是注解上的反射对象
                //withMethodAnnotation:扫描方法上的注解
                .apis(RequestHandlerSelectors.basePackage("com.six.backend.controller"))
                //配置扫描的接口
                .paths(PathSelectors.any())
                .build()
//                .additionalModels(TypeResolver.resolve())
                //enable是否启动Swagger ,false则不能在浏览器中访问
                .enable(true);
    }

    private ApiInfo apiInfo() {
        //作者信息
        Contact contact = new Contact("skyler","https://gitee.com/chongyang-zhang/gitcode.git","2998981505@qq.com");

        return new  ApiInfo("在线会商服务系统文档API文档",
                "软件工程3班第六组",
                "v1.0",
                "https://gitee.com/chongyang-zhang/gitcode.git",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>()
                );
    }

}
